package com.zhuiyun.educations.api.information.service.impl;

import com.alipay.api.kms.aliyun.utils.StringUtils;
import com.zhuiyun.educations.api.information.entity.InformationFile;
import com.zhuiyun.educations.api.information.mapper.InformationFileMapper;
import com.zhuiyun.educations.api.information.service.InformationFileService;
import com.zhuiyun.educations.util.UploadFileUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import javax.annotation.Resource;

/**
 * @ClassName InformationFileServiceImpl
 * @Description TODO 资料管理
 * @Author ys
 * @Date 2023/6/19 19:35
 **/
@Service
public class InformationFileServiceImpl implements InformationFileService {
    @Resource
    InformationFileMapper informationFileMapper;
    @Resource
    UploadFileUtils uploadFileUtils;
    /**
     * 添加
     * @param file,informationFile
     * @return
     */
    @Override
    public int informationFileAdd(MultipartRequest file, InformationFile informationFile) {
        MultipartFile file1 = file.getFile("file");
        int i=0;
        if(file!=null){
            String s = uploadFileUtils.uploadFile(file1);
            if(!StringUtils.isEmpty(s)){
                informationFile.setInformationId(s);
            }
            i=informationFileMapper.insertSelective(informationFile);
        }
        return i;
    }

}
